//
//  MyNavController.m
//  Tang
//
//  Created by 邓芮 on 15/12/3.
//  Copyright © 2015年 352324497@qq.com. All rights reserved.
//

#import "MyNavController.h"

@interface MyNavController ()

@end

@implementation MyNavController

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    [super pushViewController:viewController animated:YES];
    if (viewController.navigationItem.leftBarButtonItem == nil && [self.viewControllers count] > 1)
    {
        // 创建set 按钮
        UIButton *setButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        setButton.frame = CGRectMake(0, 0, 25, 25);
        [setButton setImage:[UIImage imageNamed:@"back"] forState:(UIControlStateNormal)];
        // 添加方法
        [setButton addTarget:self action:@selector(BackButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
        UIBarButtonItem *setBar = [[UIBarButtonItem alloc]initWithCustomView:setButton];
        viewController.navigationItem.leftBarButtonItem = setBar;
        
        // 创建 label 显示
        UILabel *setLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60, 25)];
        setLabel.text = @"Tang";
        setLabel.textColor = [UIColor orangeColor];
        // 设置 label 字体
        setLabel.font = [UIFont fontWithName:@"SnellRoundhand-Black" size:16];
        // 居左显示
        setLabel.textAlignment = NSTextAlignmentLeft;
        UIBarButtonItem *labelBar = [[UIBarButtonItem alloc]initWithCustomView:setLabel];
        viewController.navigationItem.leftBarButtonItems = @[setBar, labelBar];
    }
}

- (void)BackButtonAction:(UIButton *)btn
{
    [self popViewControllerAnimated:YES];
}




@end
